package com.example.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 扩大session作用域
 * @author GuLin
 * @date 2021-06-30 15:12
 */
@Configuration
public class GulimallSessionConfig {

    /**
     * 同域名下共享session信息,扩大cookies有效域
     * @author GuLin
     * @date 15:14 2021/6/30
     * @return org.springframework.session.web.http.CookieSerializer
     **/
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setCookieName("GULISESSIONID");
        cookieSerializer.setDomainName("gulimall.com");
        return cookieSerializer;
    }

    /**
     * json 反序列化
     * @author GuLin
     * @date 15:16 2021/6/30
     * @return org.springframework.data.redis.serializer.RedisSerializer<java.lang.Object>
     **/
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
